/*
 * @Author: wellington wellington@kreditme.id
 * @Date: 2023-11-13 16:15:47
 * @LastEditors: wellington wellington@kreditme.id
 * @LastEditTime: 2023-11-13 16:34:54
 * @FilePath: /background-removal/test.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
Function.prototype.myCall = function(thisArg, ...args){
    console.log(this)
    // 如果thisArg传进来的是非对象，转成对象
    const context = (thisArg === null || thisArg === undefined) ? globalThis : Object(thisArg)
   
    // 使用不会与第一参数属性重复的临时变量，将函数的this存储到第一参数中，然后执行
    const fn = Symbol()
    // Object.defineProperty(context, fn, {
    //     enumerable: false,
    //     value: this
    // })
    context[fn] = this
    const result = context[fn](...args)

    // 删除临时变量
    delete context.fn
    return result

}
function add(a, b) {
    console.log('realthis', this)
    return this.name + a + b
}
add.myCall({name: 1}, 2, 3)